package lumis.portal.service.serialization;

import lumis.portal.PortalException;
import lumis.portal.manager.ManagerFactory;
import lumis.portal.serialization.BaseSerializationContext;
import lumis.portal.serialization.SerializationMessageConfigNode;
import lumis.portal.service.ServiceConfig;

/**
 * Manager for Service serialization
 *
 * @version $Revision: 4986 $ $Date: 2006-11-07 00:58:19 -0200 (Tue, 07 Nov 2006) $
 * @since 4.0.7
 */
public class ServiceSerializationManager implements IServiceSerializationManager
{
	// GENERAL
	
	public SerializationMessageConfigNode getSerializationMessageConfigNode(BaseSerializationContext baseSerializationContext, ServiceConfig serviceConfig) throws PortalException
	{
		ServiceSerializationMessageConfig serviceSerializationMessageConfig = new ServiceSerializationMessageConfig();
		serviceSerializationMessageConfig.setId(serviceConfig.getId());
		String serviceName = serviceConfig.getName();
		// localize service name at serialization time, using current locale, because at deserialization time, 
		// if the service does not exist in destination portal, there will not be any available resource  
		serviceName = ManagerFactory.getLocalizationManager().localize(serviceName, serviceConfig.getResource(), baseSerializationContext.getSessionConfig().getLocale());
		serviceSerializationMessageConfig.setName(serviceName);

		SerializationMessageConfigNode serializationMessageConfigNode = new SerializationMessageConfigNode();
		serializationMessageConfigNode.setSerializationMessageConfig(serviceSerializationMessageConfig);
		
		return serializationMessageConfigNode;
	}
}
